package com.wva.servletcontext;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/demo02ServletContext")
public class Demo02ServletContext extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        /**
         *
         * 3. 域对象：共享数据
         *  setAttribute(String name,Object value) //设置数据
         *  getAttribute(String name)  //获取数据
         *  removeAttribute(String name)  //删除数据
         *
         *  域对象范围：所有用户所有请求的数据
         */
        ServletContext context = getServletContext();
        //获取数据
        Object msg = context.getAttribute("msg");
        System.out.println(msg);


    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request,response);
    }
}
